// pages/progress/progress.ts
import api from "../../utils/api"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    testingList:[] as TestingModel[],//检测列表
    page:1 as number,
    pageSize:10 as number,
    totalCount: 0 as number,
    map:{
      SUBMIT:"已提交",
      SAMPLE_RECEIVED:"样本已接收",
      TESTING:"检测中",
      REPORT_ISSUED:"已出报告"
    }
  },
  // progress详情
  toDetail(e:any) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url:"/pages/progressdetail/progressdetail?id=" + id
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.getTestingList();
  },
  async getTestingList (): Promise<void> {
    const params = {
      page: this.data.page,
      pageSize: this.data.pageSize
    }
    const res = await api.testing.getTestingList(params);
    if(res.data.code == "000") {
      if(res.data.data && res.data.data.list) {
        this.setData({
          testingList: [...this.data.testingList , ...res.data.data.list],
          totalCount: res.data.data.totalCount,
          page: this.data.page + 1
        })
      }
    }else {
      wx.showToast({
        title:res.data.message as string,
        icon:"error"
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.testingList.length == this.data.totalCount) {
      return
    }
    this.getTestingList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})